<?php

/**
 * Manage some base actions
 * @author Tuong Tran <tuong.tran@outlook.com>
 */
class SiteController extends Controller {

    public $layout = 'column1';
    public $content = array();

    /**
     * Declares class-based actions.
     */
    public function actions() {
        return array(
          // captcha action renders the CAPTCHA image displayed on the contact page
          'captcha' => array(
            'class' => 'CCaptchaAction',
            'backColor' => 0xFFFFFF,
          ),
          'page' => array(
            'class' => 'application.widgets.CViewAction',
          ),
          'newsletter' => array(
            'class' => 'application.widgets.newsletter.ANewsletter'
          )
        );
    }

    /**
     * render home page
     */
    public function actionIndex() {
        //$this->description = settings()->get('seo', 'home_description');
        //$this->keywords = settings()->get('seo', 'home_keywords');
        //page title
        //$pageTitle = settings()->get('seo', 'home_title');
        //if ($pageTitle != NULL) {
        //    $this->pageTitle = $pageTitle;
        //}
      
        $this->layout = 'mainlayout';
        $model = new LoginForm();
        $this->content['model'] = $model;
        //var_dump($model);exit();
        if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') {
            echo CActiveForm::validate($model);
            Yii::app()->end();
        }

        // collect user input data
        if (isset($_POST['LoginForm'])) {

            $model->attributes = $_POST['LoginForm'];
            // validate user input and redirect to the previous page if valid
            if ($model->validate() && $model->login())
                $this->redirect('home/view');
            //echo 'ok';
        }
        // display the login form

        if (!isset(user()->getModel()->username))
            $this->render('index', array('model' => $model));

        else{
            $this->redirect('home/view');
        }
        //$this->render('index');

    }

    public function actionAbout() {
        $this->content['widget'] = array('application.widgets.newsletter.WSitebar', 'application.widgets.newsletter.WSuccessStory');
        $this->render('about');
    }

    public function actionRegister() {

        if (r()->isPostRequest) {
            $userRegistration = new mRegistration();
            $userRegistration->aliasAttrFormWithModel($_POST);
            if ($userRegistration->validate() && $userRegistration->checkUniqueUsernameEmail()) {
                $userRegistration->insertUserProfile($_POST['txtUsername']);
                Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/essay-04-21.css");
                Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/external_site_styles.css");
                $this->render('about_general', array('profile_id' => $userRegistration->id_profile));
                //exit();
            } else
            $this->content['widget'] = array('application.widgets.newsletter.WSitebarRegister');
            $this->content['addScript'] = array('registration.js');
            $this->content['addCss'] = array('profile-04-21.css');
            $this->render('register');
        } else {
            $this->content['widget'] = array('application.widgets.newsletter.WSitebarRegister');
            $this->content['addScript'] = array('registration.js');
            $this->content['addCss'] = array('profile-04-21.css');
            $this->render('register');
        }
    }

    public function actionSearch() {
        Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/theme.css");
        Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/base.css");
        Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/css.css");

        Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/account_settings.css");
        Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/search.css");
        Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/jquery-ui.css");
        Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/chat.css");


        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/jquery-1.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/lib.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/onload.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/community.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/jquery-1.9.1.min.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/lib.json2.min.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/jquery-ui-1.9.2.custom.min.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/jquery-mods.js");

        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/peoplemedia.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/peoplemedia_rtn_slide.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/logger.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/peoplemedia.theming.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/stacktrace-min-0.3.js");

        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/jquery.ba-bbq.min.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/index.js");


        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/jquery.cookie.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/jquery.base64.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/moment.min.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/logger.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/pmchat-1.0.js?d=20131009.js");
        Yii::app()->clientScript->registerScriptFile(WWW_URL . "js/pmchat.ui-1.0.js?d=20131009.js");


        $this->content['search'] = 1;
        $this->render('search', array('search' => 1));
    }

    public function actionTopmatchs() {
        Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/theme.css");
        Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/base.css");
        Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/profile.css");


        $this->content['topmatchs'] = 1;
        $this->render('topmatchs', array('topmatchs' => 1));
    }

    public function actionResultSearch() {
        Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/theme.css");
        Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/base.css");
        Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/search.css");


        $this->content['resultsearch'] = 1;
        $this->render('resultsearch', array('resultsearch' => 1));
    }

    public function actionListOnline() {
        Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/theme.css");
        Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/base.css");
        Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/search.css");


        $this->content['listonline'] = 1;
        $this->render('listonline', array('listonline' => 1));
    }

    public function actionRandom() {
        Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/theme.css");
        Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/base.css");
        Yii::app()->clientScript->registerCssFile(WWW_URL . "css/css1/search.css");


        $this->content['random'] = 1;
        $this->render('random', array('random' => 1));
    }

    public function actionLogin() {
        $this->content['login'] = 1;
        $this->render('login', array('model' => 1));
    }

}
